home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Temático 40 Febrero 2004.iso / DOS / ntfs / user / support.c < prev   
Encoding:
C/C++ Source or Header  |  2001-02-15  |  3.5 KB  |  186 lines

  1. /*
  2.  *  support.c
  3.  *  Specific support functions
  4.  *
  5.  *  Copyright (C) 1999 Martin von L÷wis
  6.  *  Copyright (C) 1997 RΘgis Duchesne
  7.  */
  8.  
  9. #include "ntfstypes.h"
  10. #include "struct.h"
  11. #include "support.h"
  12. #ifdef HAVE_CONFIG_H
  13. #include "config.h"
  14. #endif
  15. #ifdef MSDOS
  16. #include "../dos/readdisk.h"
  17. #endif
  18.  
  19. #include <stdlib.h>
  20. /* Solaris defines bzero() here */
  21. #ifdef HAVE_STRINGS_H
  22. #include <strings.h>
  23. #endif
  24. #ifdef HAVE_STRING_H
  25. #include <string.h>
  26. #endif
  27. #ifdef HAVE_IO_H
  28. #include <io.h>
  29. #endif
  30. #include <stdarg.h>
  31. #include <stdio.h>
  32. #include <errno.h>
  33. #ifdef HAVE_UNISTD_H
  34. #include <unistd.h>
  35. #endif
  36. #include <time.h>
  37. #include "inode.h"
  38. #include "nttools.h"
  39. #include "macros.h"
  40. #include "util.h"
  41.  
  42. int ntdebug;
  43.  
  44. void ntfs_debug(int mask, const char *fmt, ...)
  45. {
  46.     va_list args;
  47.  
  48.     if (!(mask & ntdebug))
  49.         return;
  50.     va_start( args, fmt );
  51.     vfprintf( stderr, fmt, args );
  52.     va_end (args);
  53. }
  54.  
  55. void *ntfs_malloc(int size)
  56. {
  57.     return malloc(size);
  58. }
  59.  
  60. void ntfs_free(void *block)
  61. {
  62.     free(block);
  63. }
  64.  
  65. void ntfs_bzero(void *s, int n)
  66. {
  67. #ifdef HAVE_BZERO
  68.     bzero(s, n);
  69. #else
  70. #ifdef HAVE_MEMSET
  71.     memset(s,'\0',n);
  72. #else
  73. #error no bzero implementation
  74. #endif
  75. #endif
  76. }
  77.  
  78. void ntfs_memcpy(void *dest, const void *src, ntfs_size_t n)
  79. {
  80.     memcpy(dest, src, n);
  81. }
  82.  
  83. void ntfs_memmove(void *dest, const void *src, ntfs_size_t n)
  84. {
  85.     memmove(dest, src, n);
  86. }
  87.  
  88. /* Warn that an error occured */
  89. void ntfs_error(const char *fmt,...)
  90. {
  91.     va_list ap;
  92.  
  93.     va_start(ap, fmt);
  94.     vfprintf(stderr, fmt, ap);
  95.     va_end(ap);
  96.     fputs("", stderr);
  97. }
  98.  
  99. int ntfs_read_mft_record(ntfs_volume *vol, int mftno, char *buf)
  100. {
  101.     ntfs_io io;
  102.     int error;
  103.  
  104.     io.fn_put=0;
  105.     io.fn_get=0;
  106.     /* record 0 of file 0 is always in memory */
  107.     if(mftno==0)
  108.     {
  109.         memcpy(buf,vol->mft,vol->mft_recordsize);
  110.         return 0;
  111.     }
  112.     if(!vol->mft_ino)
  113.     {
  114.         fprintf(stderr,"Cannot load mft %x without mft 0\n",mftno);
  115.         return EINVAL;
  116.     }
  117.     io.param=buf;
  118.     io.size=vol->mft_recordsize;
  119.     error=ntfs_read_attr(vol->mft_ino,vol->at_data,NULL,
  120.                mftno*vol->mft_recordsize,&io);
  121.     if(error)return error;
  122.     if(io.size!=vol->mft_recordsize)return EINVAL;
  123.     if(!ntfs_check_mft_record(vol,buf))
  124.     {
  125.         fprintf(stderr,"Inode not found\n");
  126.         return EINVAL;
  127.     }
  128.     return 0;
  129. }
  130.  
  131. /* pmemcpy is ignored here */
  132. int ntfs_getput_clusters(ntfs_volume *pvol, int cluster, ntfs_size_t offs,
  133.     ntfs_io *buf)
  134. {
  135.     int result;
  136.     if(ntfs_lseek(NTFS_FD(pvol),
  137.               pvol->partition_bias+cluster*pvol->clustersize+offs,
  138.               SEEK_SET)==-1)
  139.         return 0;
  140.     /* MAGIC: We *know* at this place that we were originally passed a plain
  141.        pointer */
  142. #ifdef MSDOS
  143.     if(buf->do_read)
  144.         result=read_dev(NTFS_FD(pvol),buf->param,buf->size);
  145.     else
  146.         result=write_dev(NTFS_FD(pvol),buf->param,buf->size);
  147. #else
  148.     if(buf->do_read)
  149.         result=read(NTFS_FD(pvol),buf->param,buf->size);
  150.     else
  151.         result=write(NTFS_FD(pvol),buf->param,buf->size);
  152. #endif
  153.     if(result==buf->size){
  154.         /* increment target pointer */
  155.         ((char*)buf->param)+=buf->size;
  156.         return 0;
  157.     }
  158.     if(result==-1)return errno;
  159.     return EIO;
  160. }
  161.  
  162. ntfs_time64_t ntfs_now(void)
  163. {
  164.     return ntfs_unixutc2ntutc(time(0));
  165. }
  166.  
  167. int ntfs_dupuni2map(ntfs_volume *vol, ntfs_u16 *in, int in_len, char **out,
  168.     int *out_len)
  169. {
  170.     /* Not supported here */
  171.     return EINVAL;
  172. }
  173.  
  174. int ntfs_dupmap2uni(ntfs_volume *vol, char* in, int in_len, ntfs_u16 **out,
  175.     int *out_len)
  176. {
  177.     /* Not supported here */
  178.     return EINVAL;
  179. }
  180.  
  181. /*
  182.  * Local variables:
  183.  * c-file-style: "linux"
  184.  * End:
  185.  */
  186.